namespace Nico {

    [GtkTemplate (ui="/de/grindhold/nico/ui/nico_client_app_main.ui")]
    public class ClientAppMain : Gtk.Box {

        [GtkChild]
        public Gtk.Switch tabak;

        [GtkChild]
        public Gtk.Switch lighter;

        [GtkChild]
        public Gtk.Switch filter;

        [GtkChild]
        public Gtk.Switch papes;

        [GtkChild]
        private Gtk.ListBox sessions;


        private Nico.Client client;


        public ClientAppMain(Nico.Client client) {
            this.client = client;
        }


        public void add_session(Nico.Session toInsertSession) {
          Nico.SessionView sessionView = new Nico.SessionView(toInsertSession);
          this.sessions.add((Gtk.Widget) sessionView);
        }

        public void remove_session(Nico.SessionView toDeleteSession) {
          GLib.List<Gtk.Widget> sessionList = this.sessions.get_children();
          int index = 0;
          while(index < sessionList.length()) {
              Nico.SessionView sessionView = (Nico.SessionView) sessionList.nth_data(index);
              if(sessionView.id == toDeleteSession.id) {
                this.sessions.remove((Gtk.Widget) sessionView);
              }
              index++;
          }
        }

        public GLib.List<Nico.SessionView> get_sessions() {
          GLib.List<Nico.SessionView> sessionViews = new GLib.List<Nico.SessionView>();
          foreach(Gtk.Widget widget in this.sessions.get_children()) {
			  Gtk.Widget w = ((Gtk.ListBoxRow)widget).get_child();
              Nico.SessionView session = (Nico.SessionView) w;
              if (session != null) {
                  sessionViews.append(session);
                }
          }
          return sessionViews;
        }
    }
}
